<template>
  <div class="GRiskRankDetail">
    <zyInfoPanel :title="type=='add'?'新增风险评估排行':'风险评估排行详情'" :showUnfoldButton="false" class="baseInfo">
      <slot name="title" v-if="type=='detail'">
        <div class="btnBox">
          <zy-button @click="download">下载</zy-button>
          <zy-button @click="toPut">推送</zy-button>
        </div>
      </slot>
      <div class="baseCont" v-if="type=='add'">
        <div class="form-box">
          <div class="form-item">
            <div class="form-label required">排行名称</div>
            <zy-input class="form-cont" v-model="risk_assmessment_name" placeholder="请输入排行名称"
                      :clearable="true"></zy-input>
          </div>
          <div class="form-item">
            <div class="form-label required">统计对象</div>
            <el-select class="form-cont" v-model="risk_assmessment_obj">
              <el-option v-for="option in optionList" :key="option.value" :label="option.label"
                         :value="option.value"></el-option>
            </el-select>
          </div>
          <div class="form-item">
            <div class="form-label required">统计时间</div>
            <datePicker class="form-cont" v-model="time" type="daterange"></datePicker>
          </div>
        </div>
        <div class="btnArea" v-if="type=='add'">
          <zy-button @click="reset">重置</zy-button>
          <zy-button @click="create">生成</zy-button>
        </div>
      </div>
      <div class="detail">
        <h1 class="risk_assmessment_name">{{detail.risk_assmessment_name}}</h1>
        <h2 class="risk_assmessment_obj_str">统计对象：{{detail.risk_assmessment_obj_str}}</h2>
        <h3 class="time_desc">统计时间：{{detail.time_desc}}</h3>
        <tablePanel tableName="GRiskRankDetailTable" :tableLoading="loading" tableTitle="" :isShowDrop="false"
                    :tableList="tableList" :tableData="tableData" :total="total" :currentPage="form.page_start"
                    :pageSize="form.page_size"
                    @sizeChange="sizeChange" @pageChange="pageChange">
        </tablePanel>
      </div>
      <div class="btnBox">
        <zy-button @click="back">{{type=='detail'?'返回':'取消'}}</zy-button>
        <zy-button @click="save" v-if="type=='add'" type="primary">保存</zy-button>
      </div>
    </zyInfoPanel>
  </div>
</template>

<script>
	import datePicker from "@/components/datePicker/index";

	export default {
		name: "GRiskRankDetail",
		props: {},
		data() {
			return {
				type: '',
				risk_assmessment_name: '',
				risk_assmessment_obj: '',
				time: [],
				optionList: [
					{label: '物流企业', value: '1'},
					{label: '合作站点', value: '2'},
					{label: '从业人员', value: '3'},
					{label: '监管辖区', value: '4'},
					{label: '高危人员', value: '5'},
					{label: '高危物品', value: '6'},
					{label: '高危线路', value: '7'},
					{label: '高危电话', value: '8'},
					{label: '高危行为', value: '9'},
				],
				detail: {
					risk_assmessment_name: '',
					risk_assmessment_obj_str: '',
					time_desc: ''
				},
				form: {
					risk_assmessment_name: '',
					risk_assmessment_obj: '',
					create_name: "",
					time: [],
					ctime: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList1: [
					{
						title: '企业名称',
						width: 120,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						width: 120,
						name: 'company_sn',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						width: 120,
						name: 'organization_code',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危人员收寄件数',
						width: 120,
						name: 'judge_person_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危物品收寄件数',
						width: 120,
						name: 'judge_good_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危线路收寄件数',
						width: 120,
						name: 'judge_region_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危电话收寄件数',
						width: 120,
						name: 'judge_phone_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危行为收寄件数',
						width: 120,
						name: 'judge_action_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList2: [
					{
						title: '合作站点名称',
						width: 120,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						width: 120,
						name: 'organization_code',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危人员收寄件数',
						width: 120,
						name: 'judge_person_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危物品收寄件数',
						width: 120,
						name: 'judge_good_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危线路收寄件数',
						width: 120,
						name: 'judge_region_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危电话收寄件数',
						width: 120,
						name: 'judge_phone_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危行为收寄件数',
						width: 120,
						name: 'judge_action_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList3: [
					{
						title: '人员姓名',
						width: 120,
						name: 'employee_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系电话',
						width: 180,
						name: 'employee_mobile',
						isShow: true,
						isSelected: true
					},
					{
						title: '所属企业',
						width: 200,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						width: 120,
						name: 'company_type',
						isShow: true,
						isSelected: true
					},
					{
						title: '职位',
						width: 120,
						name: 'profession_str',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危人员收寄件数',
						width: 120,
						name: 'judge_person_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危物品收寄件数',
						width: 120,
						name: 'judge_good_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危线路收寄件数',
						width: 120,
						name: 'judge_region_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危电话收寄件数',
						width: 120,
						name: 'judge_phone_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危行为收寄件数',
						width: 120,
						name: 'judge_action_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList4: [
					{
						title: '辖区名称',
						width: 120,
						name: 'regulated_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系电话',
						width: 120,
						name: 'regulated_mobile',
						isShow: true,
						isSelected: true
					},
					{
						title: '辖区地址',
						width: 120,
						name: 'regulated_address',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危人员收寄件数',
						width: 120,
						name: 'judge_person_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危物品收寄件数',
						width: 120,
						name: 'judge_good_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危线路收寄件数',
						width: 120,
						name: 'judge_region_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危电话收寄件数',
						width: 120,
						name: 'judge_phone_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '高危行为收寄件数',
						width: 120,
						name: 'judge_action_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList5: [
					{
						title: '高危人员姓名',
						width: 120,
						name: 'person_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '性别',
						width: 120,
						name: 'sex_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系电话',
						width: 180,
						name: 'connect_mobile',
						isShow: true,
						isSelected: true
					},
					{
						title: '身份证号',
						width: 200,
						name: 'card_no',
						isShow: true,
						isSelected: true
					},
					{
						title: '职业',
						width: 180,
						name: 'profession',
						isShow: true,
						isSelected: true
					},
					{
						title: '案件类别',
						width: 120,
						name: 'casetype',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 120,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 120,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计件数',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList6: [
					{
						title: '物品名称',
						width: 150,
						name: 'goods_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '物品类型',
						width: 150,
						name: 'goods_type',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 120,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 120,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计件数',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList7: [
					{
						title: '地区名称',
						width: 220,
						name: 'region_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 120,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 120,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计件数',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList8: [
					{
						title: '联系电话',
						width: 180,
						name: 'judge_phone',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 120,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 120,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计件数',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList9: [
					{
						title: '高危行为名称',
						width: 120,
						name: 'judge_action_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '寄件数量',
						width: 120,
						name: 'send_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '收件数量',
						width: 120,
						name: 'rec_count',
						isShow: true,
						isSelected: true
					},
					{
						title: '共计件数',
						width: 120,
						name: 'logist_num',
						isShow: true,
						isSelected: true
					},
				],
				tableList: [],
				tableData: [],
				total: 0,
				download_url:''
			};
		},
		computed: {},
		watch: {},
		components: {datePicker},
		methods: {
			download() {
				this.$import_excal(this.download_url || "");
			},
			toPut() {
				this.$toRoutePath({
					path: "/notification_list/notification_detail",
					edit: true,
					query: {risk_assmessment_name:this.risk_assmessment_name,type:'put'}
				});
			},
			reset() {
				this.risk_assmessment_name = '';
				this.risk_assmessment_obj = '';
				this.time = [];
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.save()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.save()
			},
			back(isRefresh) {
				this.$blackRoute({
					path: '/risk_rank_list',
					that: this,
					name: 'GRiskRankList',
					params: {isRefresh}
				})
			},
			save() {
				this.$axios.post(this.$api.g_saveRiskAssmessmentInfo, {
					risk_assmessment_name: this.risk_assmessment_name,
					risk_assmessment_obj: this.risk_assmessment_obj,
					start_time: this.time[0] / 1000 || '',
					end_time: this.time[1] / 1000 || ''
				}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.back(true)
					} else {
						this.$message.error(msg)
					}
				}).catch(ret => {
					this.$message.error(ret.msg || "服务繁忙，请稍后再试");
				});
			},
			create() {
				if (this.type == 'add') {
					if (!this.risk_assmessment_name) return this.$message.error('请输入排行名称')
					if (!this.risk_assmessment_obj) return this.$message.error('请选择统计对象')
					if (this.time && this.time.length == 0) return this.$message.error('请选择统计时间')
				}
				let postUrl = [
					'',
					this.$api.g_getCompanyRiskAssmessmentReport,
					this.$api.g_getCooperRiskAssmessmentReport,
					this.$api.g_getEmployeeRiskAssmessmentReport,
					this.$api.g_getRegulatedRiskAssmessmentReport,
					this.$api.g_getPersonRiskAssmessmentReport,
					this.$api.g_getGoodRiskAssmessmentReport,
					this.$api.g_getRegionRiskAssmessmentReport,
					this.$api.g_getPhoneRiskAssmessmentReport,
					this.$api.g_getActionRiskAssmessmentReport,
				]
				let postData = {
					risk_assmessment_name: this.risk_assmessment_name || '',
					risk_assmessment_obj: this.risk_assmessment_obj || '',
					l_post_date_start: this.time[0] / 1000 || '',
					l_post_date_end: this.time[1] / 1000 || '',
				}
				this.$axios.post(postUrl[this.risk_assmessment_obj], {...postData}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.detail = {
							risk_assmessment_name: this.risk_assmessment_name,
							time_desc: this.$Timestamp(this.time[0]) + ' ~ ' + this.$Timestamp(this.time[1])
						}
						this.optionList.forEach(item => {
							if (item.value == this.risk_assmessment_obj) {
								this.detail.risk_assmessment_obj_str = item.label
							}
						})
						let arr = ['保密', '男', '女'];
						this.tableList = this[`tableList${this.risk_assmessment_obj}`]
						this.tableData = data.list.filter(item => {
							item.sex_desc = arr[item.sex]
							return item;
						});
						this.total = data.pagination.total_count || 0;
						this.download_url = data.download_url || ''
					} else {
						this.$message.error(msg)
					}
				}).catch(ret => {
					this.$message.error(ret.msg || "服务繁忙，请稍后再试");
				});
			},

		},
		mounted() {
			this.type = this.$route.query.type || ''
			this.risk_assmessment_name = this.$route.query.risk_assmessment_name || '';
			this.risk_assmessment_obj = this.$route.query.risk_assmessment_obj || '';
			this.time = this.$route.query.time || []
      if(this.type=='detail'){
      	this.create();
      }
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/riskAssessmentManage/rankDetail/index.less">

</style>
